﻿// Decompiled with JetBrains decompiler
// Type: TaleWorlds.CampaignSystem.Hero
// Assembly: TaleWorlds.CampaignSystem, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
// MVID: E85F8C15-4DF6-4E9C-A58A-29177E40D07A
// Assembly location: D:\steam\steamapps\common\Mount & Blade II Bannerlord\bin\Win64_Shipping_Client\TaleWorlds.CampaignSystem.dll

using Helpers;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Xml;
using System.Xml.Serialization;
using TaleWorlds.CampaignSystem.Actions;
using TaleWorlds.CampaignSystem.CharacterDevelopment;
using TaleWorlds.CampaignSystem.Extensions;
using TaleWorlds.CampaignSystem.Issues;
using TaleWorlds.CampaignSystem.LogEntries;
using TaleWorlds.CampaignSystem.Map;
using TaleWorlds.CampaignSystem.Party;
using TaleWorlds.CampaignSystem.Party.PartyComponents;
using TaleWorlds.CampaignSystem.Settlements;
using TaleWorlds.CampaignSystem.Settlements.Workshops;
using TaleWorlds.Core;
using TaleWorlds.Library;
using TaleWorlds.Localization;
using TaleWorlds.ObjectSystem;
using TaleWorlds.SaveSystem;
using TaleWorlds.SaveSystem.Load;

#nullable disable
namespace TaleWorlds.CampaignSystem
{
  public sealed class Hero : MBObjectBase, ITrackableCampaignObject, ITrackableBase, IRandomOwner
  {
    [SaveableField(120)]
    public int LastTimeStampForActivity;
    public const int MaximumNumberOfVolunteers = 6;
    [SaveableField(130)]
    public CharacterObject[] VolunteerTypes;
    [SaveableField(160)]
    private float _passedTimeAtHomeSettlement;
    [SaveableField(170)]
    private CharacterObject _characterObject;
    [SaveableField(180)]
    private TextObject _firstName;
    [SaveableField(181)]
    private TextObject _name;
    [SaveableField(201)]
    public string HairTags = "";
    [SaveableField(202)]
    public string BeardTags = "";
    [SaveableField(203)]
    public string TattooTags = "";
    [SaveableField(260)]
    private Hero.CharacterStates _heroState;
    [SaveableField(270)]
    private CharacterTraits _heroTraits;
    [SaveableField(280)]
    private CharacterPerks _heroPerks;
    [SaveableField(290)]
    private CharacterSkills _heroSkills;
    [SaveableField(301)]
    private CharacterAttributes _characterAttributes;
    internal bool IsNobleForOldSaves;
    [SaveableField(370)]
    public int Level;
    public const int HeroWoundedHealthLevel = 20;
    [SaveableField(380)]
    private Clan _companionOf;
    [SaveableField(420)]
    public int SpcDaysInLocation;
    [SaveableField(430)]
    private int _health;
    [SaveableField(441)]
    private float _defaultAge;
    [SaveableField(440)]
    private CampaignTime _birthDay;
    [SaveableField(450)]
    private CampaignTime _deathDay;
    [SaveableField(460)]
    private float _power;
    [SaveableField(500)]
    private Clan _clan;
    [SaveableField(510)]
    private Clan _supporterOf;
    [SaveableField(520)]
    private Town _governorOf;
    [SaveableField(530)]
    private MBList<Workshop> _ownedWorkshops = new MBList<Workshop>();
    [SaveableField(551)]
    public CultureObject Culture;
    [XmlIgnore]
    [SaveableField(560)]
    private MobileParty _partyBelongedTo;
    [SaveableField(580)]
    private Settlement _stayingInSettlement;
    [SaveableField(590)]
    public MBList<ItemObject> SpecialItems;
    [SaveableField(412)]
    private bool _isKnownToPlayer;
    [SaveableField(610)]
    private bool _hasMet;
    [SaveableField(630)]
    private Settlement _bornSettlement;
    [CachedData]
    private Settlement _homeSettlement;
    [SaveableField(650)]
    private int _gold;
    [SaveableField(700)]
    private Hero _father;
    [SaveableField(710)]
    private Hero _mother;
    [SaveableField(720)]
    private readonly MBList<Hero> _exSpouses;
    [SaveableField(730)]
    private Hero _spouse;
    [SaveableField(740)]
    private readonly MBList<Hero> _children = new MBList<Hero>();
    [SaveableField(760)]
    public bool IsPregnant;
    [SaveableField(770)]
    private IHeroDeveloper _heroDeveloper;

    internal static void AutoGeneratedStaticCollectObjectsHero(
      object o,
      List<object> collectedObjects)
    {
      ((MBObjectBase) o).AutoGeneratedInstanceCollectObjects(collectedObjects);
    }

    protected override void AutoGeneratedInstanceCollectObjects(List<object> collectedObjects)
    {
      base.AutoGeneratedInstanceCollectObjects(collectedObjects);
      collectedObjects.Add((object) this.VolunteerTypes);
      collectedObjects.Add((object) this.Culture);
      collectedObjects.Add((object) this.SpecialItems);
      collectedObjects.Add((object) this._characterObject);
      collectedObjects.Add((object) this._firstName);
      collectedObjects.Add((object) this._name);
      collectedObjects.Add((object) this._heroTraits);
      collectedObjects.Add((object) this._heroPerks);
      collectedObjects.Add((object) this._heroSkills);
      collectedObjects.Add((object) this._characterAttributes);
      collectedObjects.Add((object) this._companionOf);
      CampaignTime.AutoGeneratedStaticCollectObjectsCampaignTime((object) this._birthDay, collectedObjects);
      CampaignTime.AutoGeneratedStaticCollectObjectsCampaignTime((object) this._deathDay, collectedObjects);
      collectedObjects.Add((object) this._clan);
      collectedObjects.Add((object) this._supporterOf);
      collectedObjects.Add((object) this._governorOf);
      collectedObjects.Add((object) this._ownedWorkshops);
      collectedObjects.Add((object) this._partyBelongedTo);
      collectedObjects.Add((object) this._stayingInSettlement);
      collectedObjects.Add((object) this._bornSettlement);
      collectedObjects.Add((object) this._father);
      collectedObjects.Add((object) this._mother);
      collectedObjects.Add((object) this._exSpouses);
      collectedObjects.Add((object) this._spouse);
      collectedObjects.Add((object) this._children);
      collectedObjects.Add((object) this._heroDeveloper);
      StaticBodyProperties.AutoGeneratedStaticCollectObjectsStaticBodyProperties((object) this.StaticBodyProperties, collectedObjects);
      collectedObjects.Add((object) this.EncyclopediaText);
      collectedObjects.Add((object) this._battleEquipment);
      collectedObjects.Add((object) this._civilianEquipment);
      CampaignTime.AutoGeneratedStaticCollectObjectsCampaignTime((object) this.CaptivityStartTime, collectedObjects);
      collectedObjects.Add((object) this.DeathMarkKillerHero);
      collectedObjects.Add((object) this.LastKnownClosestSettlement);
      collectedObjects.Add((object) this.PartyBelongedToAsPrisoner);
      CampaignTime.AutoGeneratedStaticCollectObjectsCampaignTime((object) this.LastMeetingTimeWithPlayer, collectedObjects);
    }

    internal static object AutoGeneratedGetMemberValueStaticBodyProperties(object o)
    {
      return (object) ((Hero) o).StaticBodyProperties;
    }

    internal static object AutoGeneratedGetMemberValueWeight(object o)
    {
      return (object) ((Hero) o).Weight;
    }

    internal static object AutoGeneratedGetMemberValueBuild(object o) => (object) ((Hero) o).Build;

    internal static object AutoGeneratedGetMemberValueEncyclopediaText(object o)
    {
      return (object) ((Hero) o).EncyclopediaText;
    }

    internal static object AutoGeneratedGetMemberValueIsFemale(object o)
    {
      return (object) ((Hero) o).IsFemale;
    }

    internal static object AutoGeneratedGetMemberValue_battleEquipment(object o)
    {
      return (object) ((Hero) o)._battleEquipment;
    }

    internal static object AutoGeneratedGetMemberValue_civilianEquipment(object o)
    {
      return (object) ((Hero) o)._civilianEquipment;
    }

    internal static object AutoGeneratedGetMemberValueCaptivityStartTime(object o)
    {
      return (object) ((Hero) o).CaptivityStartTime;
    }

    internal static object AutoGeneratedGetMemberValuePreferredUpgradeFormation(object o)
    {
      return (object) ((Hero) o).PreferredUpgradeFormation;
    }

    internal static object AutoGeneratedGetMemberValueIsMinorFactionHero(object o)
    {
      return (object) ((Hero) o).IsMinorFactionHero;
    }

    internal static object AutoGeneratedGetMemberValueOccupation(object o)
    {
      return (object) ((Hero) o).Occupation;
    }

    internal static object AutoGeneratedGetMemberValueDeathMark(object o)
    {
      return (object) ((Hero) o).DeathMark;
    }

    internal static object AutoGeneratedGetMemberValueDeathMarkKillerHero(object o)
    {
      return (object) ((Hero) o).DeathMarkKillerHero;
    }

    internal static object AutoGeneratedGetMemberValueLastKnownClosestSettlement(object o)
    {
      return (object) ((Hero) o).LastKnownClosestSettlement;
    }

    internal static object AutoGeneratedGetMemberValueLastExaminedLogEntryID(object o)
    {
      return (object) ((Hero) o).LastExaminedLogEntryID;
    }

    internal static object AutoGeneratedGetMemberValuePartyBelongedToAsPrisoner(object o)
    {
      return (object) ((Hero) o).PartyBelongedToAsPrisoner;
    }

    internal static object AutoGeneratedGetMemberValueLastMeetingTimeWithPlayer(object o)
    {
      return (object) ((Hero) o).LastMeetingTimeWithPlayer;
    }

    internal static object AutoGeneratedGetMemberValueRandomValue(object o)
    {
      return (object) ((Hero) o).RandomValue;
    }

    internal static object AutoGeneratedGetMemberValueLastTimeStampForActivity(object o)
    {
      return (object) ((Hero) o).LastTimeStampForActivity;
    }

    internal static object AutoGeneratedGetMemberValueVolunteerTypes(object o)
    {
      return (object) ((Hero) o).VolunteerTypes;
    }

    internal static object AutoGeneratedGetMemberValueHairTags(object o)
    {
      return (object) ((Hero) o).HairTags;
    }

    internal static object AutoGeneratedGetMemberValueBeardTags(object o)
    {
      return (object) ((Hero) o).BeardTags;
    }

    internal static object AutoGeneratedGetMemberValueTattooTags(object o)
    {
      return (object) ((Hero) o).TattooTags;
    }

    internal static object AutoGeneratedGetMemberValueLevel(object o) => (object) ((Hero) o).Level;

    internal static object AutoGeneratedGetMemberValueSpcDaysInLocation(object o)
    {
      return (object) ((Hero) o).SpcDaysInLocation;
    }

    internal static object AutoGeneratedGetMemberValueCulture(object o)
    {
      return (object) ((Hero) o).Culture;
    }

    internal static object AutoGeneratedGetMemberValueSpecialItems(object o)
    {
      return (object) ((Hero) o).SpecialItems;
    }

    internal static object AutoGeneratedGetMemberValueIsPregnant(object o)
    {
      return (object) ((Hero) o).IsPregnant;
    }

    internal static object AutoGeneratedGetMemberValue_passedTimeAtHomeSettlement(object o)
    {
      return (object) ((Hero) o)._passedTimeAtHomeSettlement;
    }

    internal static object AutoGeneratedGetMemberValue_characterObject(object o)
    {
      return (object) ((Hero) o)._characterObject;
    }

    internal static object AutoGeneratedGetMemberValue_firstName(object o)
    {
      return (object) ((Hero) o)._firstName;
    }

    internal static object AutoGeneratedGetMemberValue_name(object o) => (object) ((Hero) o)._name;

    internal static object AutoGeneratedGetMemberValue_heroState(object o)
    {
      return (object) ((Hero) o)._heroState;
    }

    internal static object AutoGeneratedGetMemberValue_heroTraits(object o)
    {
      return (object) ((Hero) o)._heroTraits;
    }

    internal static object AutoGeneratedGetMemberValue_heroPerks(object o)
    {
      return (object) ((Hero) o)._heroPerks;
    }

    internal static object AutoGeneratedGetMemberValue_heroSkills(object o)
    {
      return (object) ((Hero) o)._heroSkills;
    }

    internal static object AutoGeneratedGetMemberValue_characterAttributes(object o)
    {
      return (object) ((Hero) o)._characterAttributes;
    }

    internal static object AutoGeneratedGetMemberValue_companionOf(object o)
    {
      return (object) ((Hero) o)._companionOf;
    }

    internal static object AutoGeneratedGetMemberValue_health(object o)
    {
      return (object) ((Hero) o)._health;
    }

    internal static object AutoGeneratedGetMemberValue_defaultAge(object o)
    {
      return (object) ((Hero) o)._defaultAge;
    }

    internal static object AutoGeneratedGetMemberValue_birthDay(object o)
    {
      return (object) ((Hero) o)._birthDay;
    }

    internal static object AutoGeneratedGetMemberValue_deathDay(object o)
    {
      return (object) ((Hero) o)._deathDay;
    }

    internal static object AutoGeneratedGetMemberValue_power(object o)
    {
      return (object) ((Hero) o)._power;
    }

    internal static object AutoGeneratedGetMemberValue_clan(object o) => (object) ((Hero) o)._clan;

    internal static object AutoGeneratedGetMemberValue_supporterOf(object o)
    {
      return (object) ((Hero) o)._supporterOf;
    }

    internal static object AutoGeneratedGetMemberValue_governorOf(object o)
    {
      return (object) ((Hero) o)._governorOf;
    }

    internal static object AutoGeneratedGetMemberValue_ownedWorkshops(object o)
    {
      return (object) ((Hero) o)._ownedWorkshops;
    }

    internal static object AutoGeneratedGetMemberValue_partyBelongedTo(object o)
    {
      return (object) ((Hero) o)._partyBelongedTo;
    }

    internal static object AutoGeneratedGetMemberValue_stayingInSettlement(object o)
    {
      return (object) ((Hero) o)._stayingInSettlement;
    }

    internal static object AutoGeneratedGetMemberValue_isKnownToPlayer(object o)
    {
      return (object) ((Hero) o)._isKnownToPlayer;
    }

    internal static object AutoGeneratedGetMemberValue_hasMet(object o)
    {
      return (object) ((Hero) o)._hasMet;
    }

    internal static object AutoGeneratedGetMemberValue_bornSettlement(object o)
    {
      return (object) ((Hero) o)._bornSettlement;
    }

    internal static object AutoGeneratedGetMemberValue_gold(object o) => (object) ((Hero) o)._gold;

    internal static object AutoGeneratedGetMemberValue_father(object o)
    {
      return (object) ((Hero) o)._father;
    }

    internal static object AutoGeneratedGetMemberValue_mother(object o)
    {
      return (object) ((Hero) o)._mother;
    }

    internal static object AutoGeneratedGetMemberValue_exSpouses(object o)
    {
      return (object) ((Hero) o)._exSpouses;
    }

    internal static object AutoGeneratedGetMemberValue_spouse(object o)
    {
      return (object) ((Hero) o)._spouse;
    }

    internal static object AutoGeneratedGetMemberValue_children(object o)
    {
      return (object) ((Hero) o)._children;
    }

    internal static object AutoGeneratedGetMemberValue_heroDeveloper(object o)
    {
      return (object) ((Hero) o)._heroDeveloper;
    }

    [SaveableProperty(100)]
    internal StaticBodyProperties StaticBodyProperties { get; set; }

    [SaveableProperty(111)]
    public float Weight { get; set; }

    [SaveableProperty(112)]
    public float Build { get; set; }

    public BodyProperties BodyProperties
    {
      get
      {
        return new BodyProperties(new DynamicBodyProperties(this.Age, this.Weight, this.Build), this.StaticBodyProperties);
      }
    }

    public float PassedTimeAtHomeSettlement
    {
      get => this._passedTimeAtHomeSettlement;
      set => this._passedTimeAtHomeSettlement = value;
    }

    public bool CanHaveRecruits => Campaign.Current.Models.VolunteerModel.CanHaveRecruits(this);

    public CharacterObject CharacterObject => this._characterObject;

    public void SetCharacterObject(CharacterObject characterObject)
    {
      this._characterObject = characterObject;
      this.SetInitialValuesFromCharacter(this._characterObject);
    }

    public TextObject FirstName => this._firstName;

    public TextObject Name => this._name;

    public void SetName(TextObject fullName, TextObject firstName)
    {
      this._name = fullName;
      this._firstName = firstName;
      if (this.PartyBelongedTo == null || this.PartyBelongedTo.LeaderHero != this)
        return;
      this.PartyBelongedTo.PartyComponent.ClearCachedName();
    }

    [SaveableProperty(190)]
    public TextObject EncyclopediaText { get; set; }

    public string EncyclopediaLink
    {
      get
      {
        return Campaign.Current.EncyclopediaManager.GetIdentifier(typeof (Hero)) + "-" + this.StringId ?? "";
      }
    }

    public TextObject EncyclopediaLinkWithName
    {
      get => HyperlinkTexts.GetHeroHyperlinkText(this.EncyclopediaLink, this.Name);
    }

    [SaveableProperty(200)]
    public bool IsFemale { get; private set; }

    public void UpdatePlayerGender(bool isFemale) => this.IsFemale = isFemale;

    [SaveableProperty(210)]
    private Equipment _battleEquipment { get; set; }

    [SaveableProperty(220)]
    private Equipment _civilianEquipment { get; set; }

    public Equipment BattleEquipment
    {
      get => this._battleEquipment ?? Campaign.Current.DeadBattleEquipment;
    }

    public Equipment CivilianEquipment
    {
      get => this._civilianEquipment ?? Campaign.Current.DeadCivilianEquipment;
    }

    [SaveableProperty(240)]
    public CampaignTime CaptivityStartTime { get; set; }

    [SaveableProperty(800)]
    public FormationClass PreferredUpgradeFormation { get; set; }

    public Hero.CharacterStates HeroState
    {
      get => this._heroState;
      private set => this.ChangeState(value);
    }

    public CharacterTraits GetHeroTraits() => this._heroTraits;

    [SaveableProperty(320)]
    public bool IsMinorFactionHero { get; set; }

    public IssueBase Issue { get; private set; }

    public void OnIssueCreatedForHero(IssueBase issue) => this.Issue = issue;

    public void OnIssueDeactivatedForHero() => this.Issue = (IssueBase) null;

    public override string ToString() => this.Name.ToString();

    public bool CanBeCompanion => this.IsWanderer && this.CompanionOf == null;

    public bool IsNoncombatant
    {
      get
      {
        return this.GetSkillValue(DefaultSkills.OneHanded) < 50 && this.GetSkillValue(DefaultSkills.TwoHanded) < 50 && this.GetSkillValue(DefaultSkills.Polearm) < 50 && this.GetSkillValue(DefaultSkills.Throwing) < 50 && this.GetSkillValue(DefaultSkills.Crossbow) < 50 && this.GetSkillValue(DefaultSkills.Bow) < 50;
      }
    }

    public Clan CompanionOf
    {
      get => this._companionOf;
      set
      {
        if (value == this._companionOf)
          return;
        this._homeSettlement = (Settlement) null;
        if (this._companionOf != null)
          this._companionOf.OnCompanionRemoved(this);
        this._companionOf = value;
        if (this._companionOf == null)
          return;
        this._companionOf.OnCompanionAdded(this);
      }
    }

    public IEnumerable<Hero> CompanionsInParty
    {
      get
      {
        if (this.PartyBelongedTo != null && this.Clan != null)
        {
          foreach (Hero companion in (List<Hero>) this.Clan.Companions)
          {
            if (companion.PartyBelongedTo == this.PartyBelongedTo)
              yield return companion;
          }
        }
      }
    }

    [SaveableProperty(780)]
    public Occupation Occupation { get; private set; }

    public CharacterObject Template => this.CharacterObject.OriginalCharacter;

    public bool IsDead => this.HeroState == Hero.CharacterStates.Dead;

    public bool IsFugitive => this.HeroState == Hero.CharacterStates.Fugitive;

    public bool IsPrisoner => this.HeroState == Hero.CharacterStates.Prisoner;

    public bool IsReleased => this.HeroState == Hero.CharacterStates.Released;

    public bool IsActive => this.HeroState == Hero.CharacterStates.Active;

    public bool IsNotSpawned => this.HeroState == Hero.CharacterStates.NotSpawned;

    public bool IsDisabled => this.HeroState == Hero.CharacterStates.Disabled;

    public bool IsTraveling => this.HeroState == Hero.CharacterStates.Traveling;

    public bool IsAlive => !this.IsDead;

    [SaveableProperty(400)]
    public KillCharacterAction.KillCharacterActionDetail DeathMark { get; private set; }

    [SaveableProperty(401)]
    public Hero DeathMarkKillerHero { get; private set; }

    [SaveableProperty(411)]
    public Settlement LastKnownClosestSettlement { get; private set; }

    public void UpdateLastKnownClosestSettlement(Settlement settlement)
    {
      this.LastKnownClosestSettlement = settlement;
    }

    public void SetNewOccupation(Occupation occupation)
    {
      Occupation occupation1 = this.Occupation;
      this.Occupation = occupation;
      CampaignEventDispatcher.Instance.OnHeroOccupationChanged(this, occupation1);
    }

    public bool IsWanderer => this.Occupation == Occupation.Wanderer;

    public bool IsTemplate => this.CharacterObject.IsTemplate;

    public bool IsWounded => this.HitPoints <= 20;

    public bool IsPlayerCompanion => this.CompanionOf == Clan.PlayerClan;

    public bool IsMerchant => this.Occupation == Occupation.Merchant;

    public bool IsPreacher => this.Occupation == Occupation.Preacher;

    public bool IsHeadman => this.Occupation == Occupation.Headman;

    public bool IsGangLeader => this.Occupation == Occupation.GangLeader;

    public bool IsArtisan => this.Occupation == Occupation.Artisan;

    public bool IsRuralNotable => this.Occupation == Occupation.RuralNotable;

    public bool IsUrbanNotable
    {
      get
      {
        return this.Occupation == Occupation.Merchant || this.Occupation == Occupation.Artisan || this.Occupation == Occupation.GangLeader;
      }
    }

    public bool IsSpecial => this.Occupation == Occupation.Special;

    public bool IsRebel => this.Clan != null && this.Clan.IsRebelClan;

    public bool IsCommander => this.GetTraitLevel(DefaultTraits.Commander) > 0;

    public bool IsPartyLeader
    {
      get => this.PartyBelongedTo != null && this.PartyBelongedTo.LeaderHero == this;
    }

    public bool IsNotable
    {
      get
      {
        return this.IsArtisan || this.IsGangLeader || this.IsPreacher || this.IsMerchant || this.IsRuralNotable || this.IsHeadman;
      }
    }

    public bool IsLord => this.Occupation == Occupation.Lord;

    public int MaxHitPoints => this.CharacterObject.MaxHitPoints();

    public int HitPoints
    {
      get => this._health;
      set
      {
        if (this._health == value)
          return;
        int health = this._health;
        this._health = value;
        if (this._health < 0)
          this._health = 1;
        else if (this._health > this.CharacterObject.MaxHitPoints())
          this._health = this.CharacterObject.MaxHitPoints();
        if (health <= 20 != this._health <= 20)
        {
          if (this.PartyBelongedTo != null)
            this.PartyBelongedTo.MemberRoster.OnHeroHealthStatusChanged(this);
          if (this.PartyBelongedToAsPrisoner != null)
            this.PartyBelongedToAsPrisoner.PrisonRoster.OnHeroHealthStatusChanged(this);
        }
        if (health <= 20 || !this.IsWounded)
          return;
        CampaignEventDispatcher.Instance.OnHeroWounded(this);
      }
    }

    public CampaignTime BirthDay
    {
      get
      {
        return CampaignOptions.IsLifeDeathCycleDisabled ? CampaignTime.YearsFromNow(-this._defaultAge) : this._birthDay;
      }
    }

    public CampaignTime DeathDay
    {
      get
      {
        return CampaignOptions.IsLifeDeathCycleDisabled ? CampaignTime.YearsFromNow(-this._defaultAge) + CampaignTime.Years(this._defaultAge) : this._deathDay;
      }
      set => this._deathDay = value;
    }

    public float Age
    {
      get
      {
        if (CampaignOptions.IsLifeDeathCycleDisabled)
          return this._defaultAge;
        return this.IsAlive ? this._birthDay.ElapsedYearsUntilNow : (float) (this.DeathDay - this._birthDay).ToYears;
      }
    }

    public void SetBirthDay(CampaignTime birthday)
    {
      this._birthDay = birthday;
      this._defaultAge = birthday.IsNow ? 1f / 1000f : this._birthDay.ElapsedYearsUntilNow;
    }

    public bool IsChild
    {
      get => (double) this.Age < (double) Campaign.Current.Models.AgeModel.HeroComesOfAge;
    }

    public float Power => this._power;

    public void AddPower(float value) => this._power += value;

    public Banner ClanBanner => this.Clan?.Banner;

    [SaveableProperty(481)]
    public long LastExaminedLogEntryID { get; set; }

    public Clan Clan
    {
      get => this.CompanionOf ?? this._clan;
      set
      {
        if (this._clan == value)
          return;
        this._homeSettlement = (Settlement) null;
        if (this._clan != null)
          this._clan.OnLordRemoved(this);
        Clan clan = this._clan;
        this._clan = value;
        if (this._clan != null)
          this._clan.OnLordAdded(this);
        CampaignEventDispatcher.Instance.OnHeroChangedClan(this, clan);
      }
    }

    public Clan SupporterOf
    {
      get => this._supporterOf;
      set
      {
        if (this._supporterOf == value)
          return;
        if (this._supporterOf != null)
          this._supporterOf.OnSupporterNotableRemoved(this);
        this._supporterOf = value;
        if (this._supporterOf == null)
          return;
        this._supporterOf.OnSupporterNotableAdded(this);
      }
    }

    public Town GovernorOf
    {
      get => this._governorOf;
      set
      {
        if (value == this._governorOf)
          return;
        this._governorOf = value;
      }
    }

    public IFaction MapFaction
    {
      get
      {
        if (this.Clan != null)
          return (IFaction) this.Clan.Kingdom ?? (IFaction) this.Clan;
        if (this.IsSpecial)
          return (IFaction) null;
        if (this.HomeSettlement != null)
          return this.HomeSettlement.MapFaction;
        return this.PartyBelongedTo != null ? this.PartyBelongedTo.MapFaction : (IFaction) null;
      }
    }

    public List<Alley> OwnedAlleys { get; private set; }

    public bool IsFactionLeader => this.MapFaction != null && this.MapFaction.Leader == this;

    public bool IsKingdomLeader
    {
      get
      {
        return this.MapFaction != null && this.MapFaction.IsKingdomFaction && this.MapFaction.Leader == this;
      }
    }

    public bool IsClanLeader => this.Clan != null && this.Clan.Leader == this;

    public List<CaravanPartyComponent> OwnedCaravans { get; private set; }

    public MobileParty PartyBelongedTo
    {
      get => this._partyBelongedTo;
      private set => this.SetPartyBelongedTo(value);
    }

    [SaveableProperty(570)]
    public PartyBase PartyBelongedToAsPrisoner { get; private set; }

    public Settlement StayingInSettlement
    {
      get => this._stayingInSettlement;
      set
      {
        if (this._stayingInSettlement == value)
          return;
        if (this._stayingInSettlement != null)
        {
          this._stayingInSettlement.RemoveHeroWithoutParty(this);
          this._stayingInSettlement = (Settlement) null;
        }
        value?.AddHeroWithoutParty(this);
        this._stayingInSettlement = value;
      }
    }

    public bool IsHumanPlayerCharacter => this == Hero.MainHero;

    public bool IsKnownToPlayer
    {
      get => this._isKnownToPlayer;
      set
      {
        if (this._isKnownToPlayer == value)
          return;
        this._isKnownToPlayer = value;
        CampaignEventDispatcher.Instance.OnPlayerLearnsAboutHero(this);
      }
    }

    public bool HasMet
    {
      get => this._hasMet;
      private set
      {
        if (this._hasMet == value)
          return;
        this._hasMet = value;
        CampaignEventDispatcher.Instance.OnPlayerMetHero(this);
      }
    }

    public void SetHasMet()
    {
      this.HasMet = true;
      this.LastMeetingTimeWithPlayer = CampaignTime.Now;
    }

    [SaveableProperty(620)]
    public CampaignTime LastMeetingTimeWithPlayer { get; set; }

    public Settlement BornSettlement
    {
      get => this._bornSettlement;
      set
      {
        this._bornSettlement = value;
        this._homeSettlement = (Settlement) null;
      }
    }

    public Settlement HomeSettlement
    {
      get
      {
        if (this._homeSettlement == null)
          this.UpdateHomeSettlement();
        return this._homeSettlement;
      }
    }

    public void UpdateHomeSettlement()
    {
      if (this.GovernorOf != null)
        this._homeSettlement = this.GovernorOf.Owner.Settlement;
      else if (this.Spouse != null && this.Spouse.GovernorOf != null)
      {
        this._homeSettlement = this.Spouse.GovernorOf.Owner.Settlement;
      }
      else
      {
        foreach (Hero child in (List<Hero>) this.Children)
        {
          if (child.GovernorOf != null && child.Clan == this.Clan)
          {
            this._homeSettlement = child.GovernorOf.Owner.Settlement;
            return;
          }
        }
        if (this.Father != null && this.Father.GovernorOf != null && this.Father.Clan == this.Clan)
          this._homeSettlement = this.Father.GovernorOf.Owner.Settlement;
        else if (this.Mother != null && this.Mother.GovernorOf != null && this.Mother.Clan == this.Clan)
        {
          this._homeSettlement = this.Mother.GovernorOf.Owner.Settlement;
        }
        else
        {
          foreach (Hero sibling in this.Siblings)
          {
            if (sibling.GovernorOf != null && sibling.Clan == this.Clan)
            {
              this._homeSettlement = sibling.GovernorOf.Owner.Settlement;
              return;
            }
          }
          if (this.Clan != null)
            this._homeSettlement = this.Clan.HomeSettlement;
          else if (this.CompanionOf != null)
            this._homeSettlement = this.CompanionOf.HomeSettlement;
          else if (this.IsNotable && this.CurrentSettlement != null)
            this._homeSettlement = this.CurrentSettlement;
          else
            this._homeSettlement = this._bornSettlement;
        }
      }
    }

    public Settlement CurrentSettlement
    {
      get
      {
        Settlement currentSettlement = (Settlement) null;
        if (this.PartyBelongedTo != null)
          currentSettlement = this.PartyBelongedTo.CurrentSettlement;
        else if (this.PartyBelongedToAsPrisoner != null)
          currentSettlement = this.PartyBelongedToAsPrisoner.IsSettlement ? this.PartyBelongedToAsPrisoner.Settlement : (this.PartyBelongedToAsPrisoner.IsMobile ? this.PartyBelongedToAsPrisoner.MobileParty.CurrentSettlement : (Settlement) null);
        else if (this.StayingInSettlement != null)
          currentSettlement = this.StayingInSettlement;
        return currentSettlement;
      }
    }

    public int Gold
    {
      get => this._gold;
      set => this._gold = MathF.Max(0, value);
    }

    [SaveableProperty(660)]
    public int RandomValue { get; private set; } = MBRandom.RandomInt(1, int.MaxValue);

    public EquipmentElement BannerItem
    {
      get => this.BattleEquipment[EquipmentIndex.ExtraWeaponSlot];
      set => this.BattleEquipment[EquipmentIndex.ExtraWeaponSlot] = value;
    }

    public float ProbabilityOfDeath
    {
      get
      {
        return Campaign.Current.Models.HeroDeathProbabilityCalculationModel.CalculateHeroDeathProbability(this);
      }
    }

    public Hero Father
    {
      get => this._father;
      set
      {
        this._father = value;
        if (this._father == null)
          return;
        this._father._children.Add(this);
      }
    }

    public Hero Mother
    {
      get => this._mother;
      set
      {
        this._mother = value;
        if (this._mother == null)
          return;
        this._mother._children.Add(this);
      }
    }

    public MBReadOnlyList<Hero> ExSpouses => (MBReadOnlyList<Hero>) this._exSpouses;

    public Hero Spouse
    {
      get => this._spouse;
      set
      {
        if (this._spouse == value)
          return;
        Hero spouse = this._spouse;
        this._spouse = value;
        if (spouse != null)
        {
          this._exSpouses.Add(spouse);
          spouse.Spouse = (Hero) null;
        }
        if (this._spouse == null)
          return;
        this._spouse.Spouse = this;
      }
    }

    public MBList<Hero> Children => this._children;

    public IEnumerable<Hero> Siblings
    {
      get
      {
        Hero hero = this;
        if (hero.Father != null)
        {
          foreach (Hero child in (List<Hero>) hero.Father._children)
          {
            if (child != hero)
              yield return child;
          }
        }
        else if (hero.Mother != null)
        {
          foreach (Hero child in (List<Hero>) hero.Mother._children)
          {
            if (child != hero)
              yield return child;
          }
        }
      }
    }

    public IHeroDeveloper HeroDeveloper => this._heroDeveloper;

    public int GetSkillValue(SkillObject skill)
    {
      return this._heroSkills == null ? 0 : this._heroSkills.GetPropertyValue(skill);
    }

    public void SetSkillValue(SkillObject skill, int value)
    {
      this._heroSkills.SetPropertyValue(skill, value);
    }

    public void ClearSkills() => this._heroSkills.ClearAllProperty();

    public void AddSkillXp(SkillObject skill, float xpAmount)
    {
      this._heroDeveloper?.AddSkillXp(skill, xpAmount);
    }

    public int GetAttributeValue(CharacterAttribute charAttribute)
    {
      return this._characterAttributes == null ? 0 : this._characterAttributes.GetPropertyValue(charAttribute);
    }

    internal void SetAttributeValueInternal(CharacterAttribute charAttribute, int value)
    {
      int num = MBMath.ClampInt(value, 0, Campaign.Current.Models.CharacterDevelopmentModel.MaxAttribute);
      this._characterAttributes.SetPropertyValue(charAttribute, num);
    }

    public void ClearAttributes() => this._characterAttributes?.ClearAllProperty();

    public void SetTraitLevel(TraitObject trait, int value)
    {
      value = MBMath.ClampInt(value, trait.MinValue, trait.MaxValue);
      this._heroTraits.SetPropertyValue(trait, value);
    }

    public int GetTraitLevel(TraitObject trait)
    {
      return this._heroTraits == null ? 0 : this._heroTraits.GetPropertyValue(trait);
    }

    public void ClearTraits() => this._heroTraits.ClearAllProperty();

    internal void SetPerkValueInternal(PerkObject perk, bool value)
    {
      this._heroPerks.SetPropertyValue(perk, value ? 1 : 0);
      if (!value)
        return;
      CampaignEventDispatcher.Instance.OnPerkOpened(this, perk);
    }

    public bool GetPerkValue(PerkObject perk)
    {
      return this._heroPerks != null && this._heroPerks.GetPropertyValue(perk) != 0;
    }

    public void ClearPerks()
    {
      this._heroPerks.ClearAllProperty();
      this.HitPoints = MathF.Min(this.HitPoints, this.MaxHitPoints);
    }

    public static Hero CreateHero(string stringID)
    {
      stringID = Campaign.Current.CampaignObjectManager.FindNextUniqueStringId<Hero>(stringID);
      Hero hero = new Hero(stringID);
      Campaign.Current.CampaignObjectManager.AddHero(hero);
      return hero;
    }

    public Hero(string stringID)
    {
      this.StringId = stringID;
      this._heroDeveloper = (IHeroDeveloper) new TaleWorlds.CampaignSystem.CharacterDevelopment.HeroDeveloper(this);
      this._exSpouses = new MBList<Hero>();
      this.Init();
    }

    public Hero()
    {
      this._heroDeveloper = (IHeroDeveloper) new TaleWorlds.CampaignSystem.CharacterDevelopment.HeroDeveloper(this);
      this._exSpouses = new MBList<Hero>();
      this.Init();
    }

    public void Init()
    {
      this._battleEquipment = (Equipment) null;
      this._civilianEquipment = (Equipment) null;
      this._gold = 0;
      this.OwnedCaravans = new List<CaravanPartyComponent>();
      this.OwnedAlleys = new List<Alley>();
      this.SpecialItems = new MBList<ItemObject>();
      this._health = 1;
      this._deathDay = CampaignTime.Never;
      this.HeroState = Hero.CharacterStates.NotSpawned;
      this._heroSkills = new CharacterSkills();
      this._heroTraits = new CharacterTraits();
      this._heroPerks = new CharacterPerks();
      this._characterAttributes = new CharacterAttributes();
      this.VolunteerTypes = new CharacterObject[6];
    }

    [LoadInitializationCallback]
    private void OnLoad(MetaData metaData, ObjectLoadData objectLoadData)
    {
      this.OwnedCaravans = new List<CaravanPartyComponent>();
      this.OwnedAlleys = new List<Alley>();
      if (MBSaveLoad.IsUpdatingGameVersion && MBSaveLoad.LastLoadedGameVersion < ApplicationVersion.FromString("e1.7.3.0"))
        this.PreferredUpgradeFormation = FormationClass.NumberOfAllFormations;
      if (this._firstName == null)
        this._firstName = this.Name;
      if (!MBSaveLoad.IsUpdatingGameVersion || !(MBSaveLoad.LastLoadedGameVersion < ApplicationVersion.FromString("e1.8.0.0")))
        return;
      object memberValueBySaveId;
      bool flag;
      int num1;
      if ((memberValueBySaveId = objectLoadData.GetMemberValueBySaveId(310)) is bool)
      {
        flag = (bool) memberValueBySaveId;
        num1 = 1;
      }
      else
        num1 = 0;
      int num2 = flag ? 1 : 0;
      this.IsNobleForOldSaves = (num1 & num2) != 0;
    }

    [LateLoadInitializationCallback]
    private void OnAfterLoad(MetaData metaData, ObjectLoadData objectLoadData)
    {
      if (!MBSaveLoad.IsUpdatingGameVersion || !MBSaveLoad.LastLoadedGameVersion.IsOlderThan(ApplicationVersion.FromString("v1.2.8.31599")) || this.CharacterObject.IsTemplate || this.CharacterObject.HiddenInEncylopedia || this.PartyBelongedTo == null || this.PartyBelongedTo.LeaderHero == this || this.CharacterObject.Occupation != Occupation.Soldier && this.CharacterObject.Occupation != Occupation.Mercenary && this.CharacterObject.Occupation != Occupation.Bandit && this.CharacterObject.Occupation != Occupation.Gangster && this.CharacterObject.Occupation != Occupation.CaravanGuard && (this.CharacterObject.Occupation != Occupation.Villager || this.CharacterObject.UpgradeTargets.Length == 0))
        return;
      this.PartyBelongedTo.MemberRoster.AddToCounts(this.CharacterObject, -this.PartyBelongedTo.MemberRoster.GetTroopCount(this.CharacterObject));
    }

    protected override void PreAfterLoad()
    {
      if (!this._characterObject.IsObsolete)
      {
        this._supporterOf?.OnSupporterNotableAdded(this);
        if (this._companionOf != null)
          this._companionOf.OnCompanionAdded(this);
        else if (this._clan?.StringId != "neutral")
          this._clan?.OnLordAdded(this);
        if (this.CurrentSettlement != null && this.PartyBelongedTo == null && this.PartyBelongedToAsPrisoner == null)
          this.CurrentSettlement.AddHeroWithoutParty(this);
      }
      if (!(MBSaveLoad.LastLoadedGameVersion < ApplicationVersion.FromString("v1.1.0")) || this.FirstName == null || this.Name == null || this == Hero.MainHero)
        return;
      if (this.Name.Attributes == null || !this.Name.Attributes.ContainsKey("FIRSTNAME"))
        this.Name.SetTextVariable("FIRSTNAME", this.FirstName);
      if (this.Name.Attributes != null && this.Name.Attributes.ContainsKey("FEMALE"))
        return;
      this.Name.SetTextVariable("FEMALE", this.IsFemale ? 1 : 0);
    }

    protected override void AfterLoad()
    {
      this._heroPerks?.ClearChangedPerks(this);
      this.HeroDeveloper?.AfterLoad();
      if (MBSaveLoad.LastLoadedGameVersion.IsOlderThan(ApplicationVersion.FromString("v1.2.8.31599")))
      {
        if (this != Hero.MainHero && this.IsPrisoner && this != Hero.MainHero && this.IsPrisoner && this.PartyBelongedToAsPrisoner == null && this.CurrentSettlement != null)
          this.PartyBelongedToAsPrisoner = this.CurrentSettlement.Party;
        MobileParty mainParty = MobileParty.MainParty;
        if (this != Hero.MainHero && this.PartyBelongedTo == mainParty && !mainParty.MemberRoster.Contains(this.CharacterObject))
          MakeHeroFugitiveAction.Apply(this);
        if (mainParty.MemberRoster.Contains(this.CharacterObject) && this.PartyBelongedTo != mainParty)
        {
          mainParty.MemberRoster.RemoveTroop(this.CharacterObject, mainParty.MemberRoster.GetElementNumber(this.CharacterObject));
          if (!Campaign.Current.IssueManager.IssueSolvingCompanionList.Contains<Hero>(this))
          {
            MobileParty partyBelongedTo = this.PartyBelongedTo;
            if ((partyBelongedTo != null ? (!partyBelongedTo.IsCaravan ? 1 : 0) : 0) != 0)
              MakeHeroFugitiveAction.Apply(this);
          }
        }
        if (this.Spouse != null && (this.Spouse.Clan != this.Clan || this.Clan == null || (double) this.Age < (double) Campaign.Current.Models.AgeModel.HeroComesOfAge))
        {
          Hero spouse = this.Spouse;
          this.Spouse = (Hero) null;
          this._exSpouses.Remove(spouse);
          spouse._exSpouses.Remove(this);
          MBReadOnlyList<LogEntry> gameActionLogs = Campaign.Current.LogEntryHistory.GameActionLogs;
          for (int index = gameActionLogs.Count - 1; index >= 0; --index)
          {
            if (gameActionLogs[index] is CharacterMarriedLogEntry characterMarriedLogEntry && (characterMarriedLogEntry.IsVisibleInEncyclopediaPageOf<Hero>(this) || characterMarriedLogEntry.IsVisibleInEncyclopediaPageOf<Hero>(this)))
              Campaign.Current.LogEntryHistory.DeleteLogAtIndex(index);
          }
          Hero hero = this.Mother ?? this.Father;
          if (hero != null)
            this.Clan = hero.Clan;
          else if ((double) this.Age < (double) Campaign.Current.Models.AgeModel.HeroComesOfAge && !this.IsDead)
          {
            KillCharacterAction.ApplyByRemove(this);
          }
          else
          {
            Clan clan1 = (Clan) null;
            int num = int.MaxValue;
            for (int index = 0; index < Clan.All.Count<Clan>(); ++index)
            {
              Clan clan2 = Clan.All[index];
              if (clan2 != Clan.PlayerClan && !clan2.IsBanditFaction && !clan2.IsRebelClan && !clan2.IsEliminated && this.Culture == clan2.Culture && clan2.Heroes.Count < num)
              {
                num = clan2.Heroes.Count;
                clan1 = clan2;
              }
            }
            if (clan1 == null)
              clan1 = Clan.All.GetRandomElementWithPredicate<Clan>((Func<Clan, bool>) (currentClan => currentClan != Clan.PlayerClan && !currentClan.IsBanditFaction && !currentClan.IsRebelClan && !currentClan.IsEliminated));
            this.Clan = clan1;
          }
        }
      }
      if (MBSaveLoad.IsUpdatingGameVersion && MBSaveLoad.LastLoadedGameVersion < ApplicationVersion.FromString("v1.1.1") && !this.IsDead && this.CurrentSettlement == null && this.IsNotable && this.BornSettlement != null)
      {
        TeleportHeroAction.ApplyImmediateTeleportToSettlement(this, this.BornSettlement);
        if (!this.IsActive)
          this.ChangeState(Hero.CharacterStates.Active);
        this.UpdateHomeSettlement();
      }
      if (!MBSaveLoad.IsUpdatingGameVersion || !MBSaveLoad.LastLoadedGameVersion.IsOlderThan(ApplicationVersion.FromString("v1.2.8.31599")) || (this.CharacterObject.IsTemplate || this.CharacterObject.HiddenInEncylopedia ? 0 : (this.CharacterObject.Occupation == Occupation.Soldier || this.CharacterObject.Occupation == Occupation.Mercenary || this.CharacterObject.Occupation == Occupation.Bandit || this.CharacterObject.Occupation == Occupation.Gangster || this.CharacterObject.Occupation == Occupation.CaravanGuard ? 1 : (this.CharacterObject.Occupation != Occupation.Villager ? 0 : (this.CharacterObject.UpgradeTargets.Length != 0 ? 1 : 0)))) == 0)
        return;
      if (this.PartyBelongedTo != null)
      {
        if (this.PartyBelongedTo.LeaderHero == this)
          DestroyPartyAction.Apply((PartyBase) null, this.PartyBelongedTo);
        else
          this.PartyBelongedTo.MemberRoster.AddToCounts(this.CharacterObject, -this.PartyBelongedTo.MemberRoster.GetTroopCount(this.CharacterObject));
      }
      if (this.PartyBelongedToAsPrisoner != null)
        EndCaptivityAction.ApplyByDeath(this);
      if (this.IsAlive)
        KillCharacterAction.ApplyByRemove(this);
      Campaign.Current.CampaignObjectManager.UnregisterDeadHero(this);
      Campaign.Current.ObjectManager.UnregisterObject((MBObjectBase) this.CharacterObject);
    }

    public void ChangeState(Hero.CharacterStates newState)
    {
      Hero.CharacterStates heroState = this._heroState;
      this._heroState = newState;
      Campaign.Current.CampaignObjectManager.HeroStateChanged(this, heroState);
    }

    public bool IsHealthFull() => this.HitPoints >= this.CharacterObject.MaxHitPoints();

    private void HealByAmountInternal(int healingAmount, bool addXp = false)
    {
      if (this.IsHealthFull())
        return;
      int healingAmount1 = MathF.Min(healingAmount, this.CharacterObject.MaxHitPoints() - this.HitPoints);
      this.HitPoints += healingAmount1;
      if (!addXp)
        return;
      SkillLevelingManager.OnHeroHealedWhileWaiting(this, healingAmount1);
    }

    public void Heal(int healAmount, bool addXp = false)
    {
      this.HealByAmountInternal(Campaign.Current.Models.PartyHealingModel.GetHeroesEffectedHealingAmount(this, (float) healAmount), addXp);
    }

    public override void Deserialize(MBObjectManager objectManager, XmlNode node)
    {
      base.Deserialize(objectManager, node);
      CharacterObject characterObject = MBObjectManager.Instance.GetObject<CharacterObject>(this.StringId);
      this.SetCharacterObject(characterObject);
      this.StaticBodyProperties = this.CharacterObject.GetBodyPropertiesMin(false).StaticProperties;
      DynamicBodyProperties dynamicProperties = this.CharacterObject.GetBodyPropertiesMin(true).DynamicProperties;
      if (dynamicProperties == DynamicBodyProperties.Invalid)
        dynamicProperties = DynamicBodyProperties.Default;
      this.Weight = dynamicProperties.Weight;
      this.Build = dynamicProperties.Build;
      XmlAttribute attribute1 = node.Attributes["alive"];
      this._heroState = attribute1 != null && attribute1.Value == "false" ? Hero.CharacterStates.Dead : Hero.CharacterStates.NotSpawned;
      if (this.IsDead)
        HeroHelper.GetRandomDeathDayAndBirthDay((int) characterObject.Age, out this._birthDay, out this._deathDay);
      this.CharacterObject.HeroObject = this;
      this.Father = objectManager.ReadObjectReferenceFromXml("father", typeof (Hero), node) as Hero;
      this.Mother = objectManager.ReadObjectReferenceFromXml("mother", typeof (Hero), node) as Hero;
      if (this.Spouse == null)
        this.Spouse = objectManager.ReadObjectReferenceFromXml("spouse", typeof (Hero), node) as Hero;
      Clan clan = objectManager.ReadObjectReferenceFromXml("faction", typeof (Clan), node) as Clan;
      if (clan.StringId != "neutral")
        this.Clan = clan;
      this.EncyclopediaText = node.Attributes["text"] != null ? new TextObject(node.Attributes["text"].Value) : TextObject.Empty;
      XmlNode attribute2 = (XmlNode) node.Attributes["preferred_upgrade_formation"];
      this.PreferredUpgradeFormation = FormationClass.NumberOfAllFormations;
      FormationClass result;
      if (attribute2 != null && Enum.TryParse<FormationClass>(attribute2.InnerText, true, out result))
        this.PreferredUpgradeFormation = result;
      ItemObject itemObject = node.Attributes["banner_item"] != null ? MBObjectManager.Instance.GetObject<ItemObject>(node.Attributes["banner_item"].Value) : (ItemObject) null;
      if (itemObject != null)
        this.BannerItem = new EquipmentElement(itemObject);
      this.HeroDeveloper.InitializeHeroDeveloper();
    }

    public bool CanLeadParty()
    {
      bool result = true;
      CampaignEventDispatcher.Instance.CanHeroLeadParty(this, ref result);
      return result;
    }

    public static TextObject SetHeroEncyclopediaTextAndLinks(Hero o)
    {
      StringHelpers.SetCharacterProperties("LORD", o.CharacterObject);
      MBTextManager.SetTextVariable("TITLE", HeroHelper.GetTitleInIndefiniteCase(o), false);
      MBTextManager.SetTextVariable("REPUTATION", CharacterHelper.GetReputationDescription(o.CharacterObject), false);
      MBTextManager.SetTextVariable("FACTION_NAME", GameTexts.FindText("str_neutral_term_for_culture", o.MapFaction.IsMinorFaction ? o.Culture.StringId : o.MapFaction.Culture.StringId), false);
      if (o.MapFaction.Culture.StringId == "empire")
        MBTextManager.SetTextVariable("FACTION_NAME", "{=empirefaction}Empire", false);
      MBTextManager.SetTextVariable("CLAN_NAME", o.Clan.Name, false);
      if (o.Clan.IsMinorFaction || o.Clan.IsRebelClan)
      {
        if (o.Clan == Hero.MainHero.Clan)
          MBTextManager.SetTextVariable("CLAN_DESCRIPTION", "{=REWGj2ge}a rising new clan", false);
        else if (o.Clan.IsSect)
          MBTextManager.SetTextVariable("CLAN_DESCRIPTION", "{=IlRC9Drl}a religious sect", false);
        else if (o.Clan.IsClanTypeMercenary)
          MBTextManager.SetTextVariable("CLAN_DESCRIPTION", "{=5cH6ssDI}a mercenary company", false);
        else if (o.Clan.IsNomad)
          MBTextManager.SetTextVariable("CLAN_DESCRIPTION", "{=nt1ra97u}a nomadic clan", false);
        else if (o.Clan.IsMafia)
          MBTextManager.SetTextVariable("CLAN_DESCRIPTION", "{=EmBEupR5}a secret society", false);
        else
          MBTextManager.SetTextVariable("CLAN_DESCRIPTION", "{=KZxKVby0}an organization", false);
        return o == Hero.MainHero && o.GetTraitLevel(DefaultTraits.Mercy) == 0 && o.GetTraitLevel(DefaultTraits.Honor) == 0 && o.GetTraitLevel(DefaultTraits.Generosity) == 0 && o.GetTraitLevel(DefaultTraits.Valor) == 0 && o.GetTraitLevel(DefaultTraits.Calculating) == 0 ? new TextObject("{=FHjM62IY}{LORD.FIRSTNAME} is a member of the {CLAN_NAME}, a rising new clan. {?LORD.GENDER}She{?}He{\\?} is still making {?LORD.GENDER}her{?}his{\\?} reputation.") : new TextObject("{=9Obe3S6L}{LORD.FIRSTNAME} is a member of the {CLAN_NAME}, {CLAN_DESCRIPTION} from the lands of the {FACTION_NAME}. {?LORD.GENDER}She{?}He{\\?} has the reputation of being {REPUTATION}.");
      }
      List<Kingdom> list = Campaign.Current.Kingdoms.Where<Kingdom>((Func<Kingdom, bool>) (x => x.Culture == o.MapFaction.Culture)).ToList<Kingdom>();
      if (list.Count > 1)
        MBTextManager.SetTextVariable("RULER", o.MapFaction.Leader.Name, false);
      MBTextManager.SetTextVariable("CLAN_DESCRIPTION", "{=KzSeg8ks}a noble family", false);
      if (list.Count == 1)
        return o.Clan.Leader == o ? new TextObject("{=6d4ZTvGv}{LORD.NAME} is {TITLE} of the {FACTION_NAME} and head of the {CLAN_NAME}, {CLAN_DESCRIPTION} of the realm. {?LORD.GENDER}She{?}He{\\?} has the reputation of being {REPUTATION}.") : new TextObject("{=o5AUljbW}{LORD.NAME} is a member of the {CLAN_NAME}, {CLAN_DESCRIPTION} of the {FACTION_NAME}. {?LORD.GENDER}She{?}He{\\?} has the reputation of being {REPUTATION}.");
      if (list.Count <= 1)
        return new TextObject("{=!}Placeholder text");
      return o.Clan.Leader == o ? new TextObject("{=JuPUG5wX}{LORD.NAME} is {TITLE} of the {FACTION_NAME} and head of the {CLAN_NAME}, {CLAN_DESCRIPTION} that is backing {RULER} in the civil war. {?LORD.GENDER}She{?}He{\\?} has the reputation of being {REPUTATION}.") : new TextObject("{=0bPb5btR}{LORD.NAME} is a member of the {CLAN_NAME}, {CLAN_DESCRIPTION} of the {FACTION_NAME} that is backing {RULER} in the civil war. {?LORD.GENDER}She{?}He{\\?} has the reputation of being {REPUTATION}.");
    }

    public bool CanHeroEquipmentBeChanged()
    {
      bool result = true;
      CampaignEventDispatcher.Instance.CanHeroEquipmentBeChanged(this, ref result);
      return result;
    }

    public bool CanMarry()
    {
      if (!Campaign.Current.Models.MarriageModel.IsSuitableForMarriage(this))
        return false;
      bool result = true;
      CampaignEventDispatcher.Instance.CanHeroMarry(this, ref result);
      return result;
    }

    internal void OnDeath()
    {
      this.ClearAttributes();
      this._heroSkills = (CharacterSkills) null;
      this._heroPerks = (CharacterPerks) null;
      this._heroTraits = (CharacterTraits) null;
      this._characterAttributes = (CharacterAttributes) null;
      this._heroDeveloper = (IHeroDeveloper) null;
      this.VolunteerTypes = (CharacterObject[]) null;
      this._battleEquipment = (Equipment) null;
      this._civilianEquipment = (Equipment) null;
      this.SupporterOf = (Clan) null;
      this.DeathMarkKillerHero = (Hero) null;
      this.LastKnownClosestSettlement = (Settlement) null;
    }

    private void SetPartyBelongedTo(MobileParty party)
    {
      if (this._partyBelongedTo != party && this._partyBelongedTo != null)
      {
        if (this._partyBelongedTo.LeaderHero == this)
          this._partyBelongedTo.PartyComponent.ChangePartyLeader((Hero) null);
        this._partyBelongedTo.RemoveHeroPerkRole(this);
      }
      this._partyBelongedTo = party;
    }

    public bool CanBeGovernorOrHavePartyRole()
    {
      if (this.IsPrisoner)
        return false;
      bool result = true;
      CampaignEventDispatcher.Instance.CanBeGovernorOrHavePartyRole(this, ref result);
      return result;
    }

    public bool CanDie(
      KillCharacterAction.KillCharacterActionDetail causeOfDeath)
    {
      if (CampaignOptions.IsLifeDeathCycleDisabled && causeOfDeath == KillCharacterAction.KillCharacterActionDetail.DiedOfOldAge)
        return false;
      bool result = true;
      CampaignEventDispatcher.Instance.CanHeroDie(this, causeOfDeath, ref result);
      return result;
    }

    public bool CanBecomePrisoner()
    {
      if (this != Hero.MainHero)
        return true;
      bool result = true;
      CampaignEventDispatcher.Instance.CanHeroBecomePrisoner(this, ref result);
      return result;
    }

    public bool CanMoveToSettlement()
    {
      bool result = true;
      CampaignEventDispatcher.Instance.CanMoveToSettlement(this, ref result);
      return result;
    }

    public bool CanHaveQuestsOrIssues()
    {
      if (this.Issue != null)
        return false;
      bool result = true;
      CampaignEventDispatcher.Instance.CanHaveQuestsOrIssues(this, ref result);
      return result;
    }

    public string AssignVoice()
    {
      double age = (double) this.CharacterObject.Age;
      this.GetTraitLevel(DefaultTraits.Mercy);
      int traitLevel1 = this.GetTraitLevel(DefaultTraits.Generosity);
      this.GetTraitLevel(DefaultTraits.Valor);
      int traitLevel2 = this.GetTraitLevel(DefaultTraits.Calculating);
      int traitLevel3 = this.GetTraitLevel(DefaultTraits.Honor);
      int traitLevel4 = this.GetTraitLevel(DefaultTraits.Politician);
      int traitLevel5 = this.GetTraitLevel(DefaultTraits.Commander);
      string str1 = (string) null;
      if (!(this.CharacterObject.Culture.StringId == "empire"))
      {
        if (this.CharacterObject.Culture.StringId == "vlandia")
        {
          Clan clan = this.Clan;
          if ((clan != null ? (clan.IsNoble ? 1 : 0) : 0) != 0 || this.IsMerchant)
            goto label_3;
        }
        if (this.CharacterObject.Culture.StringId == "empire" || this.CharacterObject.Culture.StringId == "vlandia")
        {
          str1 = "lowerwest";
          goto label_10;
        }
        else if (this.CharacterObject.Culture.StringId == "sturgia" || this.CharacterObject.Culture.StringId == "battania")
        {
          str1 = "north";
          goto label_10;
        }
        else if (this.CharacterObject.Culture.StringId == "aserai" || this.CharacterObject.Culture.StringId == "khuzait")
        {
          str1 = "east";
          goto label_10;
        }
        else
          goto label_10;
      }
label_3:
      str1 = "upperwest";
label_10:
      string str2 = "earnest";
      if (traitLevel4 < 3 && traitLevel1 < 0)
        str2 = "curt";
      else if (traitLevel4 < 3 && traitLevel5 < 5)
        str2 = "softspoken";
      else if (traitLevel2 - traitLevel3 > -1)
        str2 = "ironic";
      return str2 + "_" + str1;
    }

    public void AddInfluenceWithKingdom(float additionalInfluence)
    {
      float randomFloat = MBRandom.RandomFloat;
      ChangeClanInfluenceAction.Apply(this.Clan, (float) ((int) additionalInfluence + ((double) randomFloat < (double) additionalInfluence - (double) MathF.Floor(additionalInfluence) ? 1 : 0)));
    }

    public float GetRelationWithPlayer() => (float) Hero.MainHero.GetRelation(this);

    public float GetUnmodifiedClanLeaderRelationshipWithPlayer()
    {
      return (float) Hero.MainHero.GetBaseHeroRelation(this);
    }

    public void SetTextVariables()
    {
      MBTextManager.SetTextVariable("SALUTATION_BY_PLAYER", !CharacterObject.OneToOneConversationCharacter.IsFemale ? GameTexts.FindText("str_my_lord") : GameTexts.FindText("str_my_lady"), false);
      if (!TextObject.IsNullOrEmpty(this.FirstName))
        MBTextManager.SetTextVariable("FIRST_NAME", this.FirstName, false);
      else
        MBTextManager.SetTextVariable("FIRST_NAME", this.Name, false);
      MBTextManager.SetTextVariable("GENDER", this.IsFemale ? 1 : 0);
    }

    public void SetPersonalRelation(Hero otherHero, int value)
    {
      value = MBMath.ClampInt(value, Campaign.Current.Models.DiplomacyModel.MinRelationLimit, Campaign.Current.Models.DiplomacyModel.MaxRelationLimit);
      CharacterRelationManager.SetHeroRelation(this, otherHero, value);
    }

    public int GetRelation(Hero otherHero)
    {
      return otherHero == this ? 0 : Campaign.Current.Models.DiplomacyModel.GetEffectiveRelation(this, otherHero);
    }

    public int GetBaseHeroRelation(Hero otherHero)
    {
      return Campaign.Current.Models.DiplomacyModel.GetBaseRelation(this, otherHero);
    }

    public bool IsEnemy(Hero otherHero)
    {
      return CharacterRelationManager.GetHeroRelation(this, otherHero) < Campaign.Current.Models.DiplomacyModel.MinNeutralRelationLimit;
    }

    public bool IsFriend(Hero otherHero)
    {
      return CharacterRelationManager.GetHeroRelation(this, otherHero) > Campaign.Current.Models.DiplomacyModel.MaxNeutralRelationLimit;
    }

    public bool IsNeutral(Hero otherHero) => !this.IsFriend(otherHero) && !this.IsEnemy(otherHero);

    public void ModifyHair(int hair, int beard, int tattoo)
    {
      BodyProperties bodyProperties = this.BodyProperties;
      FaceGen.SetHair(ref bodyProperties, hair, beard, tattoo);
      this.StaticBodyProperties = bodyProperties.StaticProperties;
    }

    public void ModifyPlayersFamilyAppearance(StaticBodyProperties staticBodyProperties)
    {
      this.StaticBodyProperties = staticBodyProperties;
    }

    public MBReadOnlyList<Workshop> OwnedWorkshops
    {
      get => (MBReadOnlyList<Workshop>) this._ownedWorkshops;
    }

    public void AddOwnedWorkshop(Workshop workshop)
    {
      if (this._ownedWorkshops.Contains(workshop))
        return;
      this._ownedWorkshops.Add(workshop);
    }

    public void RemoveOwnedWorkshop(Workshop workshop)
    {
      if (!this._ownedWorkshops.Contains(workshop))
        return;
      this._ownedWorkshops.Remove(workshop);
    }

    public static Hero FindFirst(Func<Hero, bool> predicate)
    {
      return Campaign.Current.Characters.FirstOrDefault<CharacterObject>((Func<CharacterObject, bool>) (x => x.IsHero && predicate(x.HeroObject)))?.HeroObject;
    }

    public static IEnumerable<Hero> FindAll(Func<Hero, bool> predicate)
    {
      return Campaign.Current.Characters.Where<CharacterObject>((Func<CharacterObject, bool>) (x => x.IsHero && predicate(x.HeroObject))).Select<CharacterObject, Hero>((Func<CharacterObject, Hero>) (x => x.HeroObject));
    }

    public static MBReadOnlyList<Hero> AllAliveHeroes => Campaign.Current.AliveHeroes;

    public static MBReadOnlyList<Hero> DeadOrDisabledHeroes
    {
      get => Campaign.Current.DeadOrDisabledHeroes;
    }

    public static Hero MainHero => CharacterObject.PlayerCharacter.HeroObject;

    public static Hero OneToOneConversationHero
    {
      get => Campaign.Current.ConversationManager.OneToOneConversationHero;
    }

    public static bool IsMainHeroIll => Campaign.Current.MainHeroIllDays != -1;

    public void MakeWounded(
      Hero killerHero = null,
      KillCharacterAction.KillCharacterActionDetail deathMarkDetail = KillCharacterAction.KillCharacterActionDetail.None)
    {
      this.DeathMark = deathMarkDetail;
      this.DeathMarkKillerHero = killerHero;
      this.HitPoints = 1;
    }

    public void AddDeathMark(
      Hero killerHero = null,
      KillCharacterAction.KillCharacterActionDetail deathMarkDetail = KillCharacterAction.KillCharacterActionDetail.None)
    {
      this.DeathMark = deathMarkDetail;
      this.DeathMarkKillerHero = killerHero;
    }

    internal void OnAddedToParty(MobileParty mobileParty)
    {
      this.PartyBelongedTo = mobileParty;
      this.StayingInSettlement = (Settlement) null;
    }

    internal void OnRemovedFromParty(MobileParty mobileParty)
    {
      this.PartyBelongedTo = (MobileParty) null;
    }

    internal void OnAddedToPartyAsPrisoner(PartyBase party)
    {
      this.PartyBelongedToAsPrisoner = party;
      this.PartyBelongedTo = (MobileParty) null;
    }

    internal void OnRemovedFromPartyAsPrisoner(PartyBase party)
    {
      this.PartyBelongedToAsPrisoner = (PartyBase) null;
    }

    TextObject ITrackableBase.GetName() => this.Name;

    public Vec3 GetPosition()
    {
      Vec3 position = Vec3.Zero;
      if (this.CurrentSettlement != null)
        position = this.CurrentSettlement.GetLogicalPosition();
      else if (this.IsPrisoner && this.PartyBelongedToAsPrisoner != null)
        position = this.PartyBelongedToAsPrisoner.IsSettlement ? this.PartyBelongedToAsPrisoner.Settlement.GetLogicalPosition() : this.PartyBelongedToAsPrisoner.MobileParty.GetLogicalPosition();
      else if (this.PartyBelongedTo != null)
        position = this.PartyBelongedTo.GetLogicalPosition();
      return position;
    }

    public IMapPoint GetMapPoint()
    {
      if (this.CurrentSettlement != null)
        return (IMapPoint) this.CurrentSettlement;
      if (!this.IsPrisoner || this.PartyBelongedToAsPrisoner == null)
        return (IMapPoint) this.PartyBelongedTo;
      return !this.PartyBelongedToAsPrisoner.IsSettlement ? (IMapPoint) this.PartyBelongedToAsPrisoner.MobileParty : (IMapPoint) this.PartyBelongedToAsPrisoner.Settlement;
    }

    public float GetTrackDistanceToMainAgent()
    {
      return this.GetPosition().Distance(Hero.MainHero.GetPosition());
    }

    public bool CheckTracked(BasicCharacterObject basicCharacter)
    {
      return this.CharacterObject == basicCharacter;
    }

    private void SetInitialValuesFromCharacter(CharacterObject characterObject)
    {
      foreach (SkillObject skill in (List<SkillObject>) Skills.All)
        this.SetSkillValue(skill, characterObject.GetSkillValue(skill));
      foreach (TraitObject trait in (List<TraitObject>) TraitObject.All)
        this.SetTraitLevel(trait, characterObject.GetTraitLevel(trait));
      this.Level = characterObject.Level;
      this.SetName(characterObject.Name, characterObject.Name);
      this.Culture = characterObject.Culture;
      this.HairTags = characterObject.HairTags;
      this.BeardTags = characterObject.BeardTags;
      this.TattooTags = characterObject.TattooTags;
      this._defaultAge = characterObject.Age;
      this._birthDay = HeroHelper.GetRandomBirthDayForAge(this._defaultAge);
      this.HitPoints = characterObject.MaxHitPoints();
      this.IsFemale = characterObject.IsFemale;
      this.Occupation = this.CharacterObject.GetDefaultOccupation();
      List<Equipment> list1 = characterObject.AllEquipments.Where<Equipment>((Func<Equipment, bool>) (t => !t.IsEmpty() && !t.IsCivilian)).ToList<Equipment>();
      List<Equipment> list2 = characterObject.AllEquipments.Where<Equipment>((Func<Equipment, bool>) (t => !t.IsEmpty() && t.IsCivilian)).ToList<Equipment>();
      if (list1.IsEmpty<Equipment>())
      {
        CultureObject cultureObject = Game.Current.ObjectManager.GetObject<CultureObject>("neutral_culture");
        list1.AddRange((IEnumerable<Equipment>) cultureObject.DefaultBattleEquipmentRoster.AllEquipments);
      }
      if (list2.IsEmpty<Equipment>())
      {
        CultureObject cultureObject = Game.Current.ObjectManager.GetObject<CultureObject>("neutral_culture");
        list2.AddRange((IEnumerable<Equipment>) cultureObject.DefaultCivilianEquipmentRoster.AllEquipments);
      }
      if (list1.IsEmpty<Equipment>() || list2.IsEmpty<Equipment>())
        return;
      Equipment equipment1 = list1[this.RandomInt(list1.Count)];
      Equipment equipment2 = list2[this.RandomInt(list2.Count)];
      this._battleEquipment = equipment1.Clone();
      this._civilianEquipment = equipment2.Clone();
    }

    public void ResetEquipments()
    {
      this._battleEquipment = this.Template.FirstBattleEquipment.Clone();
      this._civilianEquipment = this.Template.FirstCivilianEquipment.Clone();
    }

    public void ChangeHeroGold(int changeAmount)
    {
      this.Gold = changeAmount <= int.MaxValue - this._gold ? this._gold + changeAmount : int.MaxValue;
    }

    public void CheckInvalidEquipmentsAndReplaceIfNeeded()
    {
      for (int index = 0; index < 12; ++index)
      {
        Equipment battleEquipment1 = this.BattleEquipment;
        EquipmentElement equipmentElement;
        ItemObject itemObject1;
        if (battleEquipment1 == null)
        {
          itemObject1 = (ItemObject) null;
        }
        else
        {
          equipmentElement = battleEquipment1[index];
          itemObject1 = equipmentElement.Item;
        }
        ItemObject trash1 = DefaultItems.Trash;
        if (itemObject1 == trash1)
        {
          this.HandleInvalidItem(true, index);
        }
        else
        {
          Equipment battleEquipment2 = this.BattleEquipment;
          ItemObject itemObject2;
          if (battleEquipment2 == null)
          {
            itemObject2 = (ItemObject) null;
          }
          else
          {
            equipmentElement = battleEquipment2[index];
            itemObject2 = equipmentElement.Item;
          }
          if (itemObject2 != null)
          {
            equipmentElement = this.BattleEquipment[index];
            if (!equipmentElement.Item.IsReady)
            {
              MBObjectManager instance1 = MBObjectManager.Instance;
              equipmentElement = this.BattleEquipment[index];
              MBGUID id = equipmentElement.Item.Id;
              MBObjectBase mbObjectBase = instance1.GetObject(id);
              equipmentElement = this.BattleEquipment[index];
              ItemObject itemObject3 = equipmentElement.Item;
              if (mbObjectBase == itemObject3)
              {
                MBObjectManager instance2 = MBObjectManager.Instance;
                equipmentElement = this.BattleEquipment[index];
                ItemObject itemObject4 = equipmentElement.Item;
                instance2.UnregisterObject((MBObjectBase) itemObject4);
              }
              this.HandleInvalidItem(true, index);
              this.PartyBelongedTo?.ItemRoster.AddToCounts(DefaultItems.Trash, 1);
            }
            equipmentElement = this.BattleEquipment[index];
            ItemModifier itemModifier = equipmentElement.ItemModifier;
            if ((itemModifier != null ? (!itemModifier.IsReady ? 1 : 0) : 0) != 0)
              this.HandleInvalidModifier(true, index);
          }
        }
        Equipment civilianEquipment1 = this.CivilianEquipment;
        ItemObject itemObject5;
        if (civilianEquipment1 == null)
        {
          itemObject5 = (ItemObject) null;
        }
        else
        {
          equipmentElement = civilianEquipment1[index];
          itemObject5 = equipmentElement.Item;
        }
        ItemObject trash2 = DefaultItems.Trash;
        if (itemObject5 == trash2)
        {
          this.HandleInvalidItem(false, index);
        }
        else
        {
          Equipment civilianEquipment2 = this.CivilianEquipment;
          ItemObject itemObject6;
          if (civilianEquipment2 == null)
          {
            itemObject6 = (ItemObject) null;
          }
          else
          {
            equipmentElement = civilianEquipment2[index];
            itemObject6 = equipmentElement.Item;
          }
          if (itemObject6 != null)
          {
            equipmentElement = this.CivilianEquipment[index];
            if (!equipmentElement.Item.IsReady)
            {
              MBObjectManager instance3 = MBObjectManager.Instance;
              equipmentElement = this.CivilianEquipment[index];
              MBGUID id = equipmentElement.Item.Id;
              MBObjectBase mbObjectBase = instance3.GetObject(id);
              equipmentElement = this.CivilianEquipment[index];
              ItemObject itemObject7 = equipmentElement.Item;
              if (mbObjectBase == itemObject7)
              {
                MBObjectManager instance4 = MBObjectManager.Instance;
                equipmentElement = this.CivilianEquipment[index];
                ItemObject itemObject8 = equipmentElement.Item;
                instance4.UnregisterObject((MBObjectBase) itemObject8);
              }
              this.HandleInvalidItem(false, index);
              this.PartyBelongedTo?.ItemRoster.AddToCounts(DefaultItems.Trash, 1);
            }
            equipmentElement = this.CivilianEquipment[index];
            ItemModifier itemModifier = equipmentElement.ItemModifier;
            if ((itemModifier != null ? (!itemModifier.IsReady ? 1 : 0) : 0) != 0)
              this.HandleInvalidModifier(false, index);
          }
        }
      }
    }

    private void HandleInvalidItem(bool isBattleEquipment, int i)
    {
      if (this.IsHumanPlayerCharacter)
      {
        if (isBattleEquipment)
          this.BattleEquipment[i] = EquipmentElement.Invalid;
        else
          this.CivilianEquipment[i] = EquipmentElement.Invalid;
      }
      else
      {
        List<Equipment> equipmentList = isBattleEquipment ? this.CharacterObject.BattleEquipments.Where<Equipment>((Func<Equipment, bool>) (t => !t.IsEmpty())).ToList<Equipment>() : this.CharacterObject.CivilianEquipments.Where<Equipment>((Func<Equipment, bool>) (t => !t.IsEmpty())).ToList<Equipment>();
        EquipmentElement invalid = equipmentList[this.RandomInt(equipmentList.Count)][i];
        if (invalid.IsEmpty || !invalid.Item.IsReady)
          invalid = EquipmentElement.Invalid;
        if (!isBattleEquipment)
        {
          EquipmentElement equipmentElement1 = this.CivilianEquipment[i];
        }
        else
        {
          EquipmentElement equipmentElement2 = this.BattleEquipment[i];
        }
        if (isBattleEquipment)
          this.BattleEquipment[i] = invalid;
        else
          this.CivilianEquipment[i] = invalid;
      }
    }

    private void HandleInvalidModifier(bool isBattleEquipment, int i)
    {
      if (isBattleEquipment)
        this.BattleEquipment[i] = new EquipmentElement(this.BattleEquipment[i].Item);
      else
        this.CivilianEquipment[i] = new EquipmentElement(this.CivilianEquipment[i].Item);
    }

    internal void ResetClanForOldSave() => this._clan = (Clan) null;

    public enum CharacterStates
    {
      NotSpawned,
      Active,
      Fugitive,
      Prisoner,
      Released,
      Dead,
      Disabled,
      Traveling,
    }
  }
}
